package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.boby.FormBodys;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.google.gson.JsonObject;
import com.lzm.ydpt.entity.riding.PerAddress;
import com.lzm.ydpt.module.riding.activity.PerAddressActivity;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.PerAddressContract;
import com.lzm.ydpt.mvp.modelimpl.PerAddressModelImpl;

/**
 * 类名称：PerAddressPresenterImpl
 * 类描述：代理实现
 */
public class PerAddressPresenterImpl extends BasePresenter implements PerAddressContract.Presenter {

    private PerAddressContract.View mView;
    private PerAddressContract.Model mModel;

    public PerAddressPresenterImpl(PerAddressActivity context) {
        super(context);
        this.mView = context;
        this.mModel = new PerAddressModelImpl();
    }

    @Override
    public void onPerAddress(FormBodys formBodys) {
        mManager.http(mModel.onPerAddress(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<PerAddress>() {
            @Override
            public void onLoadingResult(BaseResponseBean<PerAddress> entity) {
                mView.onPerAddress(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onPerAddress"));
    }

    @Override
    public void onSaveAddress(FormBodys formBodys) {
        mManager.http(mModel.onSaveAddress(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<Integer>() {
            @Override
            public void onLoadingResult(BaseResponseBean<Integer> entity) {
                mView.onSaveAddress(entity.getMessage());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onSaveAddress"));
    }
}